Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better handle errors in static analysis #271

Merged
merged 1 commit into from
Sep 29, 2023

Conversation

giovanni-guidini
Copy link
Contributor

This was needed already.
But ultimately inspired by a user tha had the following error:

File "codecov_cli/services/staticanalysis/analyzers/python/node_wrappers.py", line 41, in do_visit
    first_if_statement = first_if_statement.children[0]
IndexError: list index out of range

Despite my best efforts, I was only able to reproduce this error using invalid Python code
(i.e. an empty if statement)

Regardless of what caused this issue in the 1st place, there may be valid reasons
for someone to have malformed code in their repo (depending what the repo is 👀)
So we should be able to still upload something and ignore the failures.

The tricky thing here is that without the static analysis data ATS can't work well.
And we can't be sure that the analyzer doesn't have bugs. I don't think this case in
particular is one of them, but I could be wrong.

So these changes actually are a way to surface processing errors AND ignore the files
that generated them, WHILE also surfacing errors to users. They are surfaced twice.
Ideally users would look at them and let us know if something is not right.

But maybe we should still fail the static analysis step in their CI? 🧐

@codecov
Copy link

codecov bot commented Sep 29, 2023

Codecov Report

Merging #271 (dfc45f5) into master (01986b6) will decrease coverage by 0.07%.
The diff coverage is 94.33%.

@@            Coverage Diff             @@
##           master     #271      +/-   ##
==========================================
- Coverage   94.95%   94.89%   -0.07%     
==========================================
  Files          78       78              
  Lines        2657     2684      +27     
==========================================
+ Hits         2523     2547      +24     
- Misses        134      137       +3     
Flag Coverage Δ
python3.10 95.21% <94.33%> (-0.07%) ⬇️
python3.11 95.20% <94.33%> (-0.07%) ⬇️
python3.8 95.21% <94.33%> (-0.07%) ⬇️
python3.9 95.21% <94.33%> (-0.07%) ⬇️
smart-labels 94.88% <94.33%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
..._cli/services/staticanalysis/analyzers/__init__.py 90.00% <100.00%> (+1.11%) ⬆️
...rvices/staticanalysis/analyzers/python/__init__.py 100.00% <100.00%> (ø)
...s/staticanalysis/analyzers/python/node_wrappers.py 100.00% <100.00%> (ø)
codecov_cli/services/staticanalysis/__init__.py 80.62% <90.32%> (+0.26%) ⬆️

This was needed already.
But ultimately inspired by a user tha had the following error:

```
File "codecov_cli/services/staticanalysis/analyzers/python/node_wrappers.py", line 41, in do_visit
    first_if_statement = first_if_statement.children[0]
IndexError: list index out of range
```

Despite my best efforts, I was only able to reproduce this error using invalid Python code
(i.e. an empty `if` statement)

Regardless of what caused this issue in the 1st place, there may be valid reasons
for someone to have malformed code in their repo (depending what the repo is 👀)
So we should be able to still upload _something_ and ignore the failures.

The tricky thing here is that without the static analysis data ATS can't work well.
And we can't be sure that the analyzer doesn't have bugs. I don't think this case in
particular is one of them, but I could be wrong.

So these changes actually are a way to surface processing errors AND ignore the files
that generated them, WHILE also surfacing errors to users. They are surfaced twice.
Ideally users would look at them and let us know if something is not right.

But maybe we should still fail the static analysis step in their CI? 🧐
@giovanni-guidini giovanni-guidini force-pushed the gio/fix-static-analysis-index-error branch from 22b4630 to dfc45f5 Compare September 29, 2023 13:59
Copy link
Contributor

@scott-codecov scott-codecov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Like we chatted about - it would make sense to me if we could catch this sort of malformed error a little higher up. i.e. when tree-sitter is parsing the source into an AST does it know that an if with no children is not valid Python?

Looks like tree-sitter-python uses the Python grammar here: https://docs.python.org/3/reference/grammar.html. Not sure how it would even parse an if statement without children since the grammar doesn't allow it.

@giovanni-guidini giovanni-guidini merged commit 6020fc0 into master Sep 29, 2023
8 of 10 checks passed
@giovanni-guidini giovanni-guidini deleted the gio/fix-static-analysis-index-error branch September 29, 2023 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants